Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a zero value when an attribute type is not recognized #1758

Merged
merged 4 commits into from
Nov 17, 2023

Conversation

sebastienblor
Copy link
Collaborator

Crashes where reported in ARNOLD-14028, which happen when we try to get the value of an attribute which type isn't supported.
At the moment, after testing specific attribute types in VtValueGet* functions, we do a blind value.Get with the type that we want to convert it to.
But apparently, this can sometimes crash in USD when the types don't match. Now, we're instead returning a 0-value when the value doesn't hold any of the types that are supported

@@ -425,7 +425,7 @@ static inline bool VtValueGetBool(const VtValue& value)
VtArray<long> array = value.UncheckedGet<VtArray<long>>();
return array.empty() ? false : (array[0] != 0);
}
return value.Get<bool>();
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something that would be great is to pass the default value as an argument:

VtValueGetBool(const VtValue &value, bool default=false) 
{ 
   ...
    return default;
}

This has the benefit of exposing the fact that the function returns a default if the value is not found ... and later on be able to change the default, as sometimes we might want true and other times false. Same for the other similar functions.
What do you think ?

CHANGELOG.md Outdated
@@ -9,6 +9,7 @@
- [usd#1077](https://github.com/Autodesk/arnold-usd/issues/1077) - Support --threads / -j argument in husk to control the amount of render threads
- [usd#658](https://github.com/Autodesk/arnold-usd/issues/658) - Support pixel aspect ratio in Hydra
- [usd#1746](https://github.com/Autodesk/arnold-usd/issues/1746) - Made the behaviour for doubleSided gprims consistent between USD and Hydra
- [usd#1758](https://github.com/Autodesk/arnold-usd/issues/1758) - Return a zero value when an attribute type is not recognized
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now it is returning a default value not necessarily zero, so may be this could be updated ?

cpichard
cpichard previously approved these changes Nov 16, 2023
@sebastienblor sebastienblor merged commit 09279f3 into Autodesk:master Nov 17, 2023
@sebastienblor sebastienblor deleted the 14028_b branch November 17, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants